package hc.bre.flow

import hc.bre.ComponentConfig
import hc.bre.cmn.RuleScriptBuilder
import hc.bre.cmn.ReferItem
import hc.bre.cmn.RuleDefinition
import hc.bre.cmn.struct.RuleResultStruct
import hc.bre.deci.tree.TreeDefinition

@groovy.transform.CompileStatic
@groovy.transform.ToString(includeNames=true)
class FlowDefinition extends RuleDefinition{
	public static final ComponentConfig _config ;
	static {
		_config = new ComponentConfig();
		_config.rtype = 'rule:flow';
		_config.rname = '决策流';
		_config.builderClass = FlowBuilder;
		_config.resultStruct = new RuleResultStruct();
		_config.objectpage = '/rule/flow/floweditor.htm?rpath=${rpath}';
		_config.description = '决策流是以流程图的方式制定决策过程。';
	}
	public static FlowDefinition create() {
		FlowDefinition ruleDef = new FlowDefinition();
		ruleDef.nodeList =[];
		FlowNodeItem start, end;

		start = new FlowNodeItem();
		start.id = ++ ruleDef.rmaxid;
		start.itemType ='start';
		start.referName = '开始';
		start.positionTop =100;
		start.positionLeft =500;
		ruleDef.nodeList.add(start);

		end = new FlowNodeItem();
		end.id = ++ ruleDef.rmaxid;
		end.itemType ='end';
		start.referName = '结束';
		end.positionTop =340;
		end.positionLeft =500;
		ruleDef.nodeList.add(end);

		ruleDef.lineList=[];
		FlowLineItem line ;
		line = new FlowLineItem();
		line.id = ++ ruleDef.rmaxid;
		line.sourceId =start.id;
		line.targetId =end.id;
		ruleDef.lineList.add(line);

		ruleDef.retList=[];
		return ruleDef;
	}

	List<FlowNodeItem> nodeList;
	List<FlowLineItem> lineList;
	List<ReferItem> retList;

	@Override
	public FlowDefinition load(Map map) {
		super.load(map);
		nodeList = hc.Util.loadList(map['nodeList'],FlowNodeItem)
		lineList = hc.Util.loadList(map['lineList'],FlowLineItem );
		retList= hc.Util.loadList(map['retList'],ReferItem );
		return this;
	}
}
